(function($) {
	 var volClass = $('input[id="planitemVolclass"]');
	 var value='';
	 if(volClass && volClass.length && volClass.length>0){
		 value = volClass[0].value;
	 }
	 
	 $('option','select[id="planitemVolclass"]').each(function(){
		 var optionValue = $(this).attr('value');
		 if(value.indexOf(',')==-1) {
			 if(value != optionValue) {
				 $(this).remove();
			 }
		 } else {
			 if(value.indexOf(optionValue+',')==0 || value.indexOf(','+optionValue+',') > 0 || value.indexOf(','+optionValue) == (value.length-optionValue.length-1)) {
			 } else if(optionValue!=''){
				 $(this).remove();
			 }
		 }
	 });
	//隐藏新建前期项目包
	if(value!=''){
		if(!(value.indexOf('0.4kV')==-1)){
			
		}else{
			$('li').each(function(index) {
  				  if($(this).text()=='新建项目包'){
  					  this.style.display='none';
  				  }
  			});
		}
	}
	

	$('#pre_plan_tab_item_00000000000037').hide();
	$('#pre_plan_tab_item_00000000000042').hide();
	
	/*
	//正在上报批次，新建项目列表隐藏中、低压配网页卡
	$('#pre_plan_tab_item_00000000000046').hide();
	$('#pre_plan_tab_item_10000000000046').hide();
	
	//正在上报批次，重报计划列表隐藏中低压配网页卡
	$('#pre_plan_tab_item_00000000000026').hide();
	
	//正在上报批次，结转列表隐藏中低压配网页卡
	$('#pre_plan_tab_item_00000000000031').hide();
	
	//正在上报批次，可研调整列表隐藏中低压配网页卡
	$('#pre_plan_tab_item_00000000000036').hide();
	
	//微调正在上报批次，新建项目列表隐藏中、低压配网页卡
	$('#pre_plan_tab_item_00000000000021').hide();
	$('#pre_plan_tab_item_10000000000021').hide();
	
	//微调正在上报批次，结转列表隐藏中低压配网页卡
	$('#pre_plan_tab_item_00000000000041').hide();
	*/
	
	/*根据电压等级隐藏标签页卡 
	 * start
	 * */
	var volclassArray = [];
	var volClasses_val = $(document.getElementsByName("paramsMap['planitemVolclass'].value")).val();
	if(volClasses_val) {
		var volClasses = volClasses_val.split(",");
	} else {
		var volClasses = [];
	}
	var zhiliu = false;
	var tentwentyunder = false;
	$.each(volClasses,function(index,value){
		if("±500kV" == value || "±800kV" == value){
			if(!zhiliu){
				zhiliu = true;
				volclassArray = volclassArray.insertAt(index,"直流");
			}
		}else if("20kV" == value || "10kV" == value || "0.4kV" == value){
			if(!tentwentyunder){
				tentwentyunder = true;
				volclassArray = volclassArray.insertAt(index,"10（20）kV及以下");
			}
		}else{
			volclassArray = volclassArray.insertAt(index,value);
		}
	})
	var newvolClasses = "";
	$.each(volclassArray,function(index,value){
		newvolClasses += value + ",";
	})
	var labelIndex = newvolClasses.lastIndexOf(",");
	newvolClasses = newvolClasses.substring(0,labelIndex);
	var textPos = 0;
	$("span","div.ui-tabs ul").each(function(index){
		if(newvolClasses.indexOf($(this).text()) == -1){
			$($(this).parents("li").get(0)).remove();
			$("#gridDiv"+$($(this).parents("li").get(0)).attr("id")).remove();
		}else{
			if(index == 0){
				textPos = newvolClasses.indexOf($(this).text());
			}
			if(newvolClasses.indexOf($(this).text()) >= textPos){
				
			}else{
				textPos = newvolClasses.indexOf($(this).text());
			}
		}
	})
	$("span","div.ui-tabs ul").each(function(index){
		if(newvolClasses.indexOf($(this).text()) == textPos){
			changeTab($($(this).parents("li").get(0)).attr("id"),true);
		}
	})	
	/*end*/
})(jQuery);

function displayBagDiv(){
	 var volClass = $('input[id="planitemVolclass"]');
	 var value='';
	 if(volClass && volClass.length && volClass.length>0){
		 value = volClass[0].value;
	 }
	 //隐藏新建前期项目包
	if(value!=''){
		if(!(value.indexOf('0.4kV')==-1)){
			
		}else{
			$('li').each(function(index) {
  				  if($(this).text()=='新建项目包'){
  					  this.style.display='none';
  				  }
  			});
		}
	}
	return "1";
}

$(function(){
	var title = '';
	var year = document.getElementById("preProjectBatch.year");
	var statusArray = document.getElementsByName("paramsMap['preProjectBatch.status'].value");
	var transmited = document.getElementById("isTransmitedFlg");
	if(year && (statusArray.length > 0 || transmited)) {
		var yearValue = year.value;
		var status = '';
		if(statusArray.length > 0) {
			status = statusArray[0].value;
		} else {
			status = '2';
		}
		var statusTitle = '';
		if(status=='0') {
			statusTitle = '正在上报';
		} else if(status=='1') {
			statusTitle = '停止上报';
		} else if(status=='2') {
			statusTitle = '已下达';
		}
		if(statusArray.length > 0) {
			title = yearValue + '年项目前期计划库';
		} else {
			title = yearValue + '年历史计划';
		}
		if(statusTitle!='') {
			title = title + '(' +statusTitle + ')';
		}
	}
	if(title!='') {
		$('#listTitle').html(title);
	}
});

Array.prototype.insertAt = function(index, value) {
	var part1 = this.slice(0, index);
	var part2 = this.slice(index);
	part1.push(value);
	return (part1.concat(part2));
};

Array.prototype.removeAt = function(index) {
	var part1 = this.slice(0, index);
	var part2 = this.slice(index);
	part1.pop();
	return (part1.concat(part2));
};